<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/simditor.css" />

		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/module.js"></script>
		<script type="text/javascript" src="js/hotkeys.js"></script>
		<script type="text/javascript" src="js/uploader.js"></script>
		<script type="text/javascript" src="js/simditor.js"></script>
	</head>
	<body>

		<div style="width: 80%;margin-left: 10%;">
			<div>
				<a href="selectList.html">文章列表</a>
				<a href="addFile.html">添加新的文章</a>
			</div>
			<div style="width: 100%;text-align: center;height: 100px;font-size: 50px;">
				<div>
					<input type="hidden" id="fileId" />
					<input style="width: 40%;height: 50px;" type="text" name="title" id="title" value="" placeholder="请输入标题" />
					<select>
						<option value="1">电当家</option>
						<option value="2">能源</option>
					</select>
				</div>
				<div>
				</div>
			</div>
			<div  style="width: 100%;text-align: center;margin-bottom: 20px">
				<button type="button" onclick="saveFile()">保存</button>
				<button type="button" onclick="cancle()">取消</button>
			</div>
			<div style="width: 80%;margin-left: 10%;">
				<textarea id="editor" placeholder="" autofocus ></textarea>
			</div>
		</div>




		<script>
			var editor = new Simditor({
				textarea: $('#editor'),
				  placeholder: '',
				  defaultImage: 'images/image.png',
				  params: {},
				  upload: false,
				  tabIndent: true,
				  toolbar: true,
				  toolbarFloat: true,
				  toolbarFloatOffset: 0,
				  toolbarHidden: false,
				  pasteImage: false,
				  cleanPaste: false
			});
			
			var  fileeId = ''
			var fileContext = ''
			
			$(document).ready(function(){
				var Ohref=window.location.href;
				fileeId = Ohref.split("?id=")[1];
				$.ajax({
					url:"http://127.0.0.1:10090/article/findById",
					type:'post',
					data:{id:fileeId},
					dataType:'json',
					success:function(data){
						//$("#context").html(data.obj.context)
						fileContext = data.obj.context
						$("#title").val(data.obj.title)
						editor.setValue(data.obj.context)
					}
				})
			}); 
		
			
			
			
			
			function saveFile(){
				var fileValue = editor.getValue();
				
				$.ajax({
					url:"http://127.0.0.1:10090/article/save",
					type:'post',
					data:{
						id:fileeId,
						title:$("#title").val(),
						context:fileValue
					},
					dataType:'json',
					success:function(data){
						if(data.flag){
							alert("保存成功")
						}else{
							alert("保存失败")
						}
					}
				})
				
			}
			
			function cancle(){
				editor.setValue(fileContext);
			}
			
			
			
			
			
		</script>
	</body>
</html>
